package com.jd.threed.死锁;


/**
 * 死锁：
 * 1. 两个线程
 * 2.一个线程拿着A 锁   等待B 锁
 * 另一个线程就一直在拿着B 锁，  等着A 锁  现实中举例，给钱吃饭
 */
public class MayDeadLock {

    Object o1 = new Object();

    Object o2 = new Object();

    public void thread1 () throws InterruptedException {
        synchronized (o1) {
            Thread.sleep(500);
            synchronized (o2) {
                System.out.println("o1 拿到两把锁");
            }
        }
    }


    public void thread2 () throws InterruptedException {
        synchronized (o2) {
            Thread.sleep(500);
            synchronized (o1) {
                System.out.println("o1 拿到两把锁");
            }
        }
    }




}
